import java.util.Arrays;

/**
* @description: 周赛306 t4
* @author hewei
* @date 2022/8/14 11:32
* @version 1.0
*/

public class CountSpecialNumbers {

    public static void main(String[] args) {
        int n = 135;
        int count = 0;
        while (n > 0) {
            n /= 10;
            ++count;
        }
        System.out.println(count);
    }

    boolean[] flag;
    public int countSpecialNumbers1(int n) {
        flag = new boolean[10];
        int ans = 0;
        for (int i = 1; i < 10; i++) {
            flag[i] = true;
            ans += process(n, i);
            flag[i] = false;
        }
        return ans;
    }

    public int process(int target, long num) {
        if (num > target) return 0;

        int res = 1;
        for (int i = 0; i <= 9; i++) {
            if (flag[i]) continue;
            flag[i] = true;
            res += process(target, num * 10 + i);
            flag[i] = false;
        }
        return res;
    }


    int[][] dp;
    char[] chars;
    public int countSpecialNumbers(int n) {
        chars = Integer.toString(n).toCharArray();
        dp = new int[chars.length][1 << 10];
        for (int i = 0; i < chars.length; i++) Arrays.fill(dp[i], -1);
        return dfs(0, 0, true, false);
    }

    public int dfs(int i, int mask, boolean isLimit, boolean isNum) {
        if (i == chars.length) return isNum ? 1 : 0;
        if (!isLimit && isNum && dp[i][mask] >= 0) return dp[i][mask];

        int res = 0;
        if (!isNum) res += dfs(i + 1, mask, false, false);
        for (int j = isNum ? 0 : 1, temp = isLimit ? chars[i] - '0' : 9; j <= temp; j++) {
            if ((mask >> j & 1) != 0) continue;
            res += dfs(i + 1, mask | (1 << j), isLimit && j == temp, true);
        }
        if (!isLimit && isNum) dp[i][mask] = res;
        return res;
    }
}
